<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <meta charset="utf-8">
    <title>${sessionScope.title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
    </style>
</head>
<body>
<div class="x-body">
    <form action="/adminSystem/saveAuthorization" method="post" class="layui-form layui-form-pane">
        <div class="layui-collapse" lay-accordion="">
            <c:forEach items="${data.data}" var="da" varStatus="ss">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">${da.key}</h2>
                    <div class="layui-input-block">
                        <c:forEach items="${da.value}" var="da2" varStatus="ss">
                            <input type="checkbox" name="id" title="${da2.name}" <c:if test="${fn:contains(authorizationUser.data,da2.id)}">checked="checked"</c:if> value="${da2.id}"
                                   class="layui-input-block">
                        </c:forEach>
                    </div>
                    <c:forEach items="${da.value}" var="da22" varStatus="sss" begin="1">
                        <c:if test="${not empty da22.button}">
                        <div class="layui-colla-content layui-show  ">
                            <div class="layui-collapse" lay-accordion="">
                                    <div class="layui-colla-item">
                                        <h2 class="layui-colla-title">${da22.name}</h2>
                                        <div class="layui-colla-content layui-show">
                                            <c:forEach items="${da22.button}" var="da33">
                                                <input type="checkbox" name="id" title="${da33.name}" <c:if test="${fn:contains(authorizationUser.data,da33.id)}">checked="checked"</c:if> value="${da33.id}"
                                                       class="layui-input-block">
                                            </c:forEach>
                                        </div>
                                    </div>
                            </div>
                        </div>
                        </c:if>
                    </c:forEach>
                </div>
            </c:forEach>
        </div>
        <br>
        <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
        <script>
            layui.use(['element','form', 'layer'], function(){
                var element = layui.element;
                var layer = layui.layer;
                var form =layui.form;
                //监听折叠
                element.on('collapse(test)', function(data){
                    layer.msg('展开状态：'+ data.show);
                });
            });
        </script>
    </form>
    <div class="layui-form-item  " style="margin-left: 50%" >
        <button class="layui-btn" lay-submit="" lay-filter="/adminSystem/saveAuthorization">保存</button>
    </div>
</div>

<input type="hidden" id="type" value="${type}">
<input type="hidden" id="authorizationUserId" value="${authorizationUserId}">
<script src="../../admin/js/jquery.min.js" charset="utf-8"></script>
<script>
    /**
     * 改变选中状态
     */

    layui.use(['form','layer','element'], function(){
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form;
        //监听提交
        form.on('submit(/adminSystem/saveAuthorization)', function(data){
            $(".layui-btn").addClass("layui-btn-disabled");
            var ids=[];
            $("input:checkbox[name='id']:checked").each(function() { // 遍历name=standard的多选框
                ids.push($(this).val());
            });
                $.ajax({
                    url:'/adminSystem/saveAuthorization',
                    type:'POST',
                    data:{
                        ids:ids,
                        userId:$("#authorizationUserId").val(),
                        type:$("#type").val()
                    },
                    timeout:5000,    //超时时间
                    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend:function(xhr){
                        tijiao=false;
                    },
                    success:function(data){
                        if(data.data=='true'){
                            layer.msg('授权成功',{icon:6,time:5000});
                            setTimeout(function () {//1秒后刷新父页面
                                window.location.reload();
                            }, 1000);

                        }else {
                            layer.msg('授权失败',{icon:5,time:1000});
                        }

                    },
                    error:function(xhr,textStatus){

                    },
                    complete:function(){
                        $(".layui-btn").removeClass("layui-btn-disabled")
                    }
                });
            return false;
        });

    });

</script>
</body>
</html>
